/*
 * @Author: szx
 * @Date: 2022-03-22 13:18:48
 * @LastEditTime: 2022-03-22 13:42:16
 * @Description:
 * @FilePath: \leetcode\剑指offer\31\31.js
 */
/**
 * @param {number[]} pushed
 * @param {number[]} popped
 * @return {boolean}
 */
var validateStackSequences = function (pushed, popped) {
    const st = [];
    const n = pushed.length;
    let i = 0,
        j = 0;
    while (i < n) {
        st.push(pushed[i++]);
        if (st.length > 0 && popped[j] == st[st.length - 1]) {
            st.pop();
            j++;
        }
    }
    return st.length > 0;
};
